Fix #696: write non-finite TOML floats as nan/inf/-inf#697
Open
seonwooj0810 wants to merge 1 commit into
Open
Conversation
TomlGenerator wrote non-finite doubles/floats via String.valueOf(), emitting Java's NaN/Infinity/-Infinity, which are not valid TOML and cannot be parsed back by the reader (fails with 'Unknown token'). Emit the TOML float tokens nan/inf/-inf instead so writer output round-trips.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #696
Root cause
TomlGenerator.writeNumber(double)andwriteNumber(float)render the value withString.valueOf(...). For non-finite values that yields Java's textual formsNaN,Infinity, and-Infinity, which are not valid TOML floats. As a result the writer produces output it cannot read back —TomlMapper.readTree(...)on the writer's own output throwsTomlStreamReadException: Unknown token.Change
Map non-finite values to the TOML float tokens
nan/inf/-inf(a small shared helper), leaving finite values formatted exactly as before. This is a writer-only change: the parser already acceptsnan,inf,+inf, and-inf(Parserline ~389), so written non-finite values now round-trip with no reader change.Tests
Added to
TomlGeneratorTest:nonFiniteDoubles/nonFiniteFloats— assert exact outputabc = nan|inf|-infnonFiniteRoundTrip— writes NaN/±Infinity and reads them back through the sameTomlMapperAll three fail before the change (two assertion failures plus a
Unknown tokenerror — the exact symptom in the issue) and pass after.Verification done:
./mvnw -pl toml -am test -Dtest=TomlGeneratorTest— 23 tests pass with the fix; reverting only theTomlGeneratorchange reproduces 2 failures + 1Unknown tokenerror.